﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Data.Objects;
using JChatData.CityMap;
using JChatData.CountryMap;
using JChatData.Helper;
using JChatData.LogMap;
using JChatData.TopicMap;
using JChatData.UserMap;
namespace JChatData.Helper
{
   public class DBConectString
    {
       /// <summary>
       /// Connect to database
       /// Code by Linh Pham
       /// </summary>
     //  public string conn;
       public ContextBuilder<ChatModel> _builder;
       public ChatModel _context;
       public DBConectString(string file)
       {
           //conn = "Data Source=DELTA-PC\\LINHDATA;Initial Catalog=Jchat;Integrated Security=True;MultipleActiveResultSets=True;";
           SqlConnection con_string = new SqlConnection(file);
           _builder = new ContextBuilder<ChatModel>();
           Registerconfig(_builder);
           _context = _builder.Create(con_string);
       }

       static void Registerconfig(ContextBuilder<ChatModel> builder)
       {
           builder.Configurations.Add(new UserMap.UserMap());
           builder.Configurations.Add(new TopicMap.TopicMap());
           builder.Configurations.Add(new LogMap.LogMap());
           builder.Configurations.Add(new CityMap.CityMap());
           builder.Configurations.Add(new CountryMap.CountryMap());
       } 
    }
}
